home *** CD-ROM | disk | FTP | other *** search
/ HAKERIS 11 / HAKERIS 11.ISO / linux / system / LinuxConsole 0.4 / linuxconsole0.4install-en.iso / linuxconsole0.4.lcm / etc / hotplug / hotplug.functions < prev    next >
Encoding:
Text File  |  2004-03-26  |  4.6 KB  |  176 lines

  1. #!/bin/bash
  2. #
  3. # Setup and utility functions for use in hotplug agents
  4. #
  5. # Most essential parameters are passed from the kernel using
  6. # environment variables.  For more information, see the docs
  7. # on-line at http://linux-hotplug.sourceforge.net or the
  8. # sources for each hotplug-aware kernel subsystem.
  9. #
  10. # $Id: hotplug.functions,v 1.11 2002/04/01 21:29:01 dbrownell Exp $
  11. #
  12.  
  13. # DEBUG=yes; export DEBUG
  14. PATH=/bin:/sbin:/usr/sbin:/usr/bin
  15.  
  16. KERNEL=`uname -r`
  17. MODULE_DIR=/lib/modules/$KERNEL
  18.  
  19. HOTPLUG_DIR=/etc/hotplug
  20.  
  21. #
  22. # for diagnostics
  23. #
  24. if [ -t -o ! -x /usr/bin/logger ]; then
  25.     mesg () {
  26.     echo "$@"
  27.     }
  28. else
  29.     mesg () {
  30.     /usr/bin/logger -t $0 "$@"
  31.     }
  32. fi
  33.  
  34. debug_mesg () {
  35.     test "$DEBUG" = no && return
  36.     mesg "$@"
  37. }
  38.  
  39. #
  40. # The modules.*map parsing uses BASH ("declare -i") and some version
  41. # of AWK, typically /bin/gawk.  Most GNU/Linux distros have these,
  42. # but some specialized ones (floppy based, etc) may not.  ("type -p"
  43. # is also a bash-ism, more robust than "which".)
  44. #
  45. AWK=`type -p gawk`
  46. if [ "$AWK" = "" ]; then
  47.     AWK=`type -p awk`
  48. fi
  49.  
  50.  
  51. #
  52. # Not "modprobe --autoclean" ... one driver module can handle many
  53. # devices.  Unloading should be done when no devices are present.
  54. # Autocleaning happens if none of the devices are open, once any of
  55. # them gets opened; wrong timing.
  56. #
  57. MODPROBE="/sbin/modprobe -s"
  58. #MODPROBE="/sbin/modprobe -vs"
  59.  
  60.  
  61. ####################################################################
  62. #
  63. # usage: load_driver type filename description
  64. #
  65. # modprobes driver module(s) if appropriate, and optionally
  66. # invokes a module-specific setup script.
  67. #
  68. # the "modules.*map" format file is guaranteed to exist
  69. #
  70. load_drivers ()
  71. {
  72.     local LOADED
  73.     DRIVERS=""
  74.  
  75.     # make this routine more readable
  76.     TYPE=$1
  77.     FILENAME=$2
  78.     DESCRIPTION=$3
  79.  
  80.     # NOTE:  usbmodules isn't currently in the trusted path; also,
  81.     # "usbutils-0.8" is needed 
  82.  
  83.     # can we use usbmodules, pcimodules?
  84.     # lister programs MIGHT be preferable to parsing from shell scripts:
  85.     # - usbmodules sees _all_ USB descriptors, may turn up more drivers
  86.     # - pcimodules works for "cold plug" case
  87.     #
  88.     # FIXME "usbmodules" could be replaced by script code parsing
  89.     # devices' "I:" lines in /proc/bus/usb/devices ... but that'd
  90.     # also have the "fails without usbfs" limitation.
  91.     #
  92.     # FIXME there's a "pcimodules" patch to the yggdrasil.com
  93.     # original, adding a per-device option; use it (and when will
  94.     # "pciutils" incorporate "pcimodules"?)
  95.     #
  96.     # FIXME PCI and USB agents should specify their own listers,
  97.     # this convention is a bit odd
  98.  
  99.     LISTER=`type -p ${TYPE}modules`
  100.     if [ "$LISTER" != "" ]; then
  101.     case $TYPE in
  102.     usb)
  103.         # only works if we have usbfs
  104.         # ... reads more descriptors than are passed in env
  105.         if [ "$DEVICE" = "" ]; then
  106.         LISTER=
  107.         else
  108.         # workaround to have usb hubs working
  109.         #DRIVERS=`$LISTER --mapfile $FILENAME --device $DEVICE`
  110.         LISTER=
  111.         fi ;;
  112.  
  113.     pci)
  114.         mesg "pcimodules is scanning more than $PCI_SLOT ..."
  115.         DRIVERS=`$LISTER`
  116.         ;;
  117.     
  118.     *)    mesg "how to invoke ${TYPE}modules ??"
  119.         LISTER=
  120.     esac
  121.     fi
  122.  
  123.     # do it with just shell scripts
  124.     if [ "$LISTER" = "" ]; then
  125.     ${TYPE}_map_modules < $FILENAME
  126.     fi
  127.  
  128.     if [ "$DRIVERS" = "" ]; then
  129.     return
  130.     fi
  131.  
  132.     # Note that DRIVERS aren't all going to be modules.
  133.     # For USB, some user-mode drivers or setup scripts may be listed.
  134.     debug_mesg Setup $DRIVERS for $DESCRIPTION
  135.  
  136.     # maybe driver modules need loading
  137.     # either kernel or user mode drivers may need to be set up
  138.     for MODULE in $DRIVERS
  139.     do
  140.     if ! lsmod | grep -q "^$MODULE "; then
  141.         if grep -q "^$MODULE\$" $HOTPLUG_DIR/blacklist \
  142.             >/dev/null 2>&1; then
  143.         debug_mesg "... blacklisted module:  $MODULE"
  144.         continue
  145.         fi
  146.         LOADED=false
  147.  
  148.         # statically linked modules aren't shown by 'lsmod',
  149.         # and user mode drivers will ONLY have a setup script;
  150.         # it's not an error if a module doesn't exist
  151.         if $MODPROBE -n $MODULE >/dev/null 2>&1 &&
  152.             ! $MODPROBE $MODULE >/dev/null 2>&1 ; then
  153.         mesg "... can't load module $MODULE"
  154.         else
  155.         # /etc/modules.conf may have set non-default module
  156.         # parameters ... handle per-device parameters in apps
  157.         # (ioctls etc) not in setup scripts or modules.conf
  158.         LOADED=true
  159.         fi
  160.  
  161.         # only run setup scripts after any matching kernel code
  162.         # has had a chance to do its thing, no matter whether it
  163.         # was dynamically or statically linked.
  164.         if [ -x $HOTPLUG_DIR/$TYPE/$MODULE ]; then
  165.         debug_mesg Module setup $MODULE for $DESCRIPTION
  166.         $HOTPLUG_DIR/$TYPE/$MODULE
  167.         LOADED=true
  168.         fi
  169.  
  170.         if [ $LOADED = false ]; then
  171.         mesg "missing kernel or user mode driver $MODULE "
  172.         fi
  173.     fi
  174.     done
  175. }
  176.